<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日期格式测试</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
        .success { color: green; }
        .error { color: red; }
        button { margin: 5px; padding: 8px 15px; }
        input, textarea { margin: 5px; padding: 5px; width: 200px; }
    </style>
</head>
<body>
    <h1>日期格式测试</h1>
    
    <div class="test-section">
        <h3>测试不同的日期格式</h3>
        <div>
            <label>用户ID:</label>
            <input type="number" id="userId" value="1">
        </div>
        <div>
            <label>活动ID:</label>
            <input type="number" id="activityId" value="1">
        </div>
        <div>
            <label>备注:</label>
            <textarea id="remark">测试预约</textarea>
        </div>
        
        <h4>测试不同的日期格式:</h4>
        <button onclick="testFormat('2025-07-22 00:00:00')">标准格式: 2025-07-22 00:00:00</button><br>
        <button onclick="testFormat('2025-07-22T00:00:00')">ISO格式: 2025-07-22T00:00:00</button><br>
        <button onclick="testFormat('2025-07-22T00:00:00.000Z')">ISO+Z格式: 2025-07-22T00:00:00.000Z</button><br>
        <button onclick="testFormat('2025-07-22 00:00')">不完整格式: 2025-07-22 00:00</button><br>
        <button onclick="testFormat('2025-07-22')">仅日期: 2025-07-22</button><br>
        
        <div id="testResult"></div>
    </div>

    <script>
        async function testFormat(dateTimeStr) {
            const bookingData = {
                userId: parseInt(document.getElementById('userId').value),
                activityId: parseInt(document.getElementById('activityId').value),
                bookingTime: dateTimeStr,
                remark: document.getElementById('remark').value
            };
            
            console.log('测试日期格式:', dateTimeStr);
            console.log('发送的数据:', bookingData);
            
            try {
                const response = await fetch('/api/booking/create', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(bookingData)
                });
                
                const result = await response.json();
                
                if (response.ok) {
                    document.getElementById('testResult').innerHTML = 
                        `<div class="success">
                            <strong>✓ 成功!</strong><br>
                            格式: ${dateTimeStr}<br>
                            响应: ${JSON.stringify(result, null, 2)}
                        </div>`;
                } else {
                    document.getElementById('testResult').innerHTML = 
                        `<div class="error">
                            <strong>✗ 失败!</strong><br>
                            格式: ${dateTimeStr}<br>
                            错误: ${JSON.stringify(result, null, 2)}
                        </div>`;
                }
            } catch (error) {
                document.getElementById('testResult').innerHTML = 
                    `<div class="error">
                        <strong>✗ 网络错误!</strong><br>
                        格式: ${dateTimeStr}<br>
                        错误: ${error.message}
                    </div>`;
            }
        }
    </script>
</body>
</html> 